require("../../assets/css/index.less");
require("./sportsData.less");
require("../../assets/fonts_three/iconfont.css");
const axios = require("axios");
require('../../utils/https');
axios.defaults.headers.common['Authorization'] = "Bearer " + JSON.parse(localStorage.getItem("token"));
const echarts = require('echarts')

function $(a) {
    return document.querySelector(a);
};
var myChart = echarts.init($('#box'));

function getecharts(x, y) {
    myChart.setOption({
        title: {
            text: '近7天运动时长',
            textStyle: {
                fontSize: 22,
            },
            width: 300,
            height: 300,
        },
        grid: {
            left: 0,
            top: "24%",
            bottom: "1%",
            containLabel: true,
        },
        tooltip: {},
        xAxis: {
            show: true,
            data: x,
            axisLabel: {
                rotate: 45
            },
            axisTick: {
                alignWithLabel: true
            }
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: y
        }],
    });
}

async function getexercise() {
    const res = await axios.get("/api/exercise")
    console.log(res.data.data.days[6].count);
    $(".bottom .calorie").innerHTML = res.data.data.days[6].sumCalorie;
    $(".bottom .day").innerHTML = res.data.data.days[6].count;
    $(".bottom .sumday").innerHTML = res.data.data.days[6].count;
    const datax = res.data.data.days.map((v) => {
        let x = v.date.slice(5)
        return x
    });
    const datay = res.data.data.days.map((v) => {
        let y = v.sumDuration
        return y
    });
    console.log(datax, datay);
    getecharts(datax, datay);
}
getexercise();

async function user() {
    const res = await axios.get("/api/user/info")
    console.log(res.data.data.calorie);
    $(".center .left span").innerHTML = res.data.data.duration;
    $(".center .right span").innerHTML = res.data.data.calorie;
}
user();

$(".icon-zuojiantou").addEventListener("click", function() {
    location.href = "/my.html";
});